# -*- coding: utf-8 -*-
from django.utils.translation import ugettext as _
from django.contrib import admin
from catalog.models import Category, Item, OperatinSystem
from feincms.admin import editor, tree_editor
from django.conf import settings

class CategoryAdmin(editor.TreeEditor):
    list_display = ('title', 'active_toggle')
    active_toggle = tree_editor.ajax_editable_boolean('active', _('is active'))
    
    def _actions_column(self, page):
        actions = super(CategoryAdmin, self)._actions_column(page)
        actions.append(u'<a href="%s/" title="%s"><img src="%simg/icon_changelink.gif" alt="%s"></a>' % (page.pk, u'Изменить категорию', settings.STATIC_URL+'admin/', u'Изменить категорию'))
        actions.append(u'<a href="add/?parent=%s" title="%s"><img src="%simg/icon_addlink.gif" alt="%s"></a>' % (page.pk, u'Добавить потомка', settings.STATIC_URL+'admin/' , u'Добавить потомка'))
        actions.append(u'<a href="%s/delete/" title="%s"><img src="%simg/icon_deletelink.gif" alt="%s"></a>' % (page.pk, u'Удалить категорию', settings.STATIC_URL+'admin/', u'Удалить категорию'))
#        actions.append(u'<a href="%s" title="%s"><img src="%simg/admin/selector-search.gif" alt="%s" /></a>' % (page.get_absolute_url(), _('View on site'), settings.ADMIN_MEDIA_PREFIX, _('View on site')))
        return actions
    def changelist_view(self, request, extra_context=None, *args, **kwargs):
        result = super(CategoryAdmin, self).changelist_view(request, extra_context=None, *args, **kwargs)
        return result
admin.site.register(Category, CategoryAdmin)

class ItemAdmin(admin.ModelAdmin):
    list_filter = ("parent", "status", "os")

admin.site.register(Item, ItemAdmin)

admin.site.register(OperatinSystem)